<template>
	<view class="coupon_container fx fx_col aic">
		<view class="pt_12" v-for="item,index in dataList" :key="index">
			<Coupon :isReceive="true" :data="item" :index="index" @received="handleReceived" @select="handleSelect" />
		</view>
		<view class="pt_38" v-if="!loading&&!dataList.length">
			<Empty type="coupon" title="暂无优惠券"/>
		</view>
	</view>
</template>

<script>
	import Coupon from '@/components/order/Coupon'
	import Empty from '@/components/Empty'
	import api from '@/service/config/api.js'
	export default {
		components: {
			Coupon,
			Empty
		},
		data() {
			return {
				dataList: [],
				loading: true,
				userInfo: this.$storage.getItem('basicUnserInfo') || {},
				platformInfo: this.$storage.getItem('platformInfo') || {},
			}
		},
		onLoad() {
			this.getData()
		},
		onShow() {
			this.platformInfo = this.$storage.getItem('platformInfo') || {}
		},
		methods: {
			getData() {
				this.$utils.loading()
				this.loading = true
				api.get('/marketing/applet/api/user/discount_coupon/list/unclaimed', {
					dealerId: this.$store.state.functionRange,
				}).then(res => {
					this.dataList = res.data
				}).finally(() => {
					this.loading = false
				})
			},
			handleSelect() {
				this.$utils.navigateBack(1)
			},
			handleReceived(data,index) {
				this.$set(this.dataList[index],'isReceive',1)
				this.$forceUpdate()
			}
		}
	}
</script>

<style lang="scss">
	@include color_page;
</style>

<style lang="scss" scoped>
</style>